angular.module('starter.myService', [])

//我的
.factory('MyService', function($http, $q) {

	return {
		//自金融历史账单
		getZjrAccountDetailList:function(page){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:accountServerAdr+"/app/account/getZjrAccountDetailList.htm",
				params:{"page":page}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		},
		//诚信宝历史账单
		getCxbAccountDetailList:function(page){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:accountServerAdr+"/app/account/getCxbAccountDetailList.htm",
				params:{"page":page}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		},
  		//修改密码
	    updateLoginPassword:function(smsCode,newPassword,certificateNo){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/updateLoginPassword.htm",
					params:{"smsCode":smsCode,"newPassword":newPassword,"certificateNo":certificateNo}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
	    //修改昵称
	    updateNickName:function(nickName){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/updateNickName.htm",
					params:{"nickName":nickName}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
		  //修改头像
	    updateHeadPic:function(headPic){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/updateHeadPic.htm",
					params:{"headPic":headPic}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
	  	//实名绑卡
	    checkCertificateNoAndBandCard:function(cardNo,cardType,province,city,name,certificateNo,bankBranch){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/checkCertificateNoAndBandCard.htm",
					params:{"cardNo":cardNo,"cardType":cardType,"province":province,"city":city,"name":name,"certificateNo":certificateNo,"bankBranch":bankBranch}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
	  	//修改银行卡
	    updateBankCard:function(cardNo,cardType,province,city,dealCode,bankBranch){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/updateBankCard.htm",
					params:{"cardNo":cardNo,"cardType":cardType,"province":province,"city":city,"dealCode":dealCode,"bankBranch":bankBranch}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  	},
	  	//修改手机号码
	    updatePhone:function(phone,smsCode,dealCode){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/updatePhone.htm",
					params:{"phone":phone,"smsCode":smsCode,"dealCode":dealCode}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
	  	//修改交易密码
	    updateDealCode:function(dealCode,smsCode){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/updateDealCode.htm",
					params:{"dealCode":dealCode,"smsCode":smsCode}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
		  //查询粉丝数和关注数
	    myAttention:function(){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:serverZjrAdr+"/app/attention/myAttention.htm"
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
		  //根据用户id查询帐户余额
	    getAccountByUserId:function(){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:accountServerAdr+"/app/account/getAccountByUserId.htm"
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		  },
		  //根据用户id查询资金明细
	    getUserAccountDetailList:function(page){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:accountServerAdr+"/app/account/getUserAccountDetailList.htm",
					params:{"page":page}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		},
		//根据用户id查询用户信息
	    getUserInfo:function(){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/getUserInfo.htm"
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		},
		//公告消息查询
		getPublicMessageList:function(page){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/getPublicMessageList.htm",
					params:{"page":page}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		},
		//我的消息查询
		getPrivateMessageList:function(page){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/getPrivateMessageList.htm",
					params:{"page":page}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
		},
		//提现
		withDrawCheckCode:function(data){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:accountServerAdr+"/app/account/withDrawCheckCode.htm",
				params:{"amount":data.amount,"dealCode":data.dealCode,"phoneCode":data.phoneCode}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		},
		//获取支付宝帐号，姓名信息
		getZhifubaoInfo:function(){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:userServerAdr+"/app/getZhifubaoInfo.htm"
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		},
		//保存支付宝流水号
		saveZhifubaoTradeRecharge:function(data){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:accountServerAdr+"/app/account/saveZhifubaoTradeRecharge.htm",
				params:{"tradeNo":data.tradeNo}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		},
		//查询黑名单
		getbreakrecordById:function(breakRecordId){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:blackServerAdr+"/app/getbreakrecordById.htm",
				params:{"breakRecordId":breakRecordId}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		},
		//通过用户id获取银行信息
		getBankInfoByUserId:function(){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:userServerAdr+"/app/getBankInfoByUserId.htm"
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		},
		//
		getRepayStatus:function(){
	  		var deferred = $q.defer();
			$http({
				method:'post',
				url:serverZjrAdr+"/app/user/getRepayStatus.htm"
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
		}
	}

})

//投资券Service
.factory('InvestmentService', function($http, $q) {
  	return {
	  //投资券列表	  
		 getLoanRedList:function(page){
	      var deferred = $q.defer();
				$http({
						method:'post',
						url:serverZjrAdr+"/app/loanRed/getLoanRedList.htm",
						params:{"page":page}
					}).success(function (response) {
						deferred.resolve(response);
					}).error(function(data) {
						deferred.reject();
				});
		   return deferred.promise;
		},
		//根据类型查询投资券列表	  
		 loanRedUsefulListByStatus:function(page,status){
	      var deferred = $q.defer();
				$http({
						method:'post',
						url:serverZjrAdr+"/app/loanRed/getLoanRedListByStatus.htm",
						params:{"page":page,"status":status}
					}).success(function (response) {
						deferred.resolve(response);
					}).error(function(data) {
						deferred.reject();
				});
		   return deferred.promise;
		},
	   //可用投资券统计	  
		 loanRedUsefulDetail:function(){
	      var deferred = $q.defer();
				$http({
						method:'post',
						url:serverZjrAdr+"/app/loanRed/countData.htm"
					}).success(function (response) {
						deferred.resolve(response);
					}).error(function(data) {
						deferred.reject();
				});
		   return deferred.promise;
		}
  };
  
})

//邀请码Service
.factory('InviteService', function($http, $q) {
		return {
			//查询自己的邀请码
		  	getInviteByUserId:function(){
		  		var deferred = $q.defer();
				$http({
					method:'post',
					url:serverZjrAdr+"/app/user/getInviteByUserId.htm"
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			      	deferred.reject();
				});
				return deferred.promise;
			},
			//提交邀请码
		  	submitInviteCode:function(inviteCode){
	  			var deferred = $q.defer();
				$http({
					method:'post',
					url:serverZjrAdr+"/app/user/submitInviteCode.htm",
					params:{"inviteCode":inviteCode}
				}).success(function (response) {
					deferred.resolve(response);
				}).error(function(data) {
				    deferred.reject();
				});
			   	return deferred.promise;
		  	},
		  	//邀请码列表人
		  	getInviteList:function(page){
		  		var deferred = $q.defer();
				$http({
					method:'post',
					url:serverZjrAdr+"/app/user/getInviteList.htm",
					params:{"page":page}
				}).success(function (response) {
					deferred.resolve(response);
				}).error(function(data) {
					deferred.reject();
				});
				return deferred.promise;
		  },
		 //邀请码二级列表人
		 getTwoInviteList:function(page,customerId){
		  		var deferred = $q.defer();
				$http({
					method:'post',
					url:serverZjrAdr+"/app/user/getTwoInviteList.htm",
					params:{"page":page,"customerId":customerId}
				}).success(function (response) {
					deferred.resolve(response);
				}).error(function(data) {
					deferred.reject();
				});
				return deferred.promise;
		  }
		  	
		};
  
})

//关注Service
.factory('AttentionService', function($http, $q) {
  return {	
    //是否已关注	  
	  isAttention:function(attentioned){
      var deferred = $q.defer();
			$http({
					method:'post',
					url:serverZjrAdr+"/app/attention/isAttention.htm",
					params:{"attentioned":attentioned}
				}).success(function (response) {
					deferred.resolve(response);
				}).error(function(data) {
					deferred.reject();
			});
	   return deferred.promise;
	 },	  
   //添加关注
	 addAttention: function(attentioned) {
      var deferred = $q.defer();
			$http({
				method:'post',
				url:serverZjrAdr+"/app/attention/addAttention.htm",
				params:{"attentioned":attentioned}
			}).success(function (response) {
			  	deferred.resolve(response);
			}).error(function(data) {
		        deferred.reject();
		  });
		   return deferred.promise;
	  },
  	//取消关注
  	deleteAttention:function(attentioned){
  		var deferred = $q.defer();
			$http({
					method:'post',
					url:serverZjrAdr+"/app/attention/deleteAttention.htm",
					params:{"attentioned":attentioned}
			}).success(function (response) {
				deferred.resolve(response);
			}).error(function(data) {
			        deferred.reject();
			});
			return deferred.promise;
	  },
	  //我关注的用户列表
  	getGzUserList:function(page){
  		var deferred = $q.defer();
			$http({
					method:'post',
					url:serverZjrAdr+"/app/attention/getGzUserList.htm",
					params:{'page':page}
			}).success(function (response) {
				deferred.resolve(response);
			}).error(function(data) {
			        deferred.reject();
			});
			return deferred.promise;
  	},
  	//关注我的粉丝列表
  	getFsUserList:function(page){
  		var deferred = $q.defer();
			$http({
					method:'post',
					url:serverZjrAdr+"/app/attention/getFsUserList.htm",
					params:{'page':page}
			}).success(function (response) {
				deferred.resolve(response);
			}).error(function(data) {
			        deferred.reject();
			});
			return deferred.promise;
  	}
  };  
})
.factory('BankNameByCardNoService',function($http,$q){
	return {
		  //获取银行卡名
	    getBankNameByCardNo:function(cardNo){
	  		var deferred = $q.defer();
				$http({
					method:'post',
					url:userServerAdr+"/app/getBankNameByCardNo.htm",
					params:{'cardNo':cardNo}
					}).success(function (response) {
					  	deferred.resolve(response);
					}).error(function(data) {
				       deferred.reject();
					});
		   		return deferred.promise;
	  }
	};
})


